/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.datamining.api;

import java.util.HashSet;
import java.util.Set;

public class Cluster {

    private Set<Vector> vectors;
    private Vector mean;
    private Vector sum; // FOR MEAN

    public Cluster(int vectorsSize) {
        this.vectors = new HashSet<Vector>();
        sum = new Vector(new double[vectorsSize]);
    }

    public void setMean(Vector mean) {
        this.mean = mean;
    }

    public void addVector(Vector vector) {
        vectors.add(vector);
        // add to sum
        for (int i = 0; i < vector.data.length; i++) {
            sum.data[i] += vector.data[i];
        }
    }

    public void remove(Vector vector) {
        vectors.remove(vector);
        // remove from sum
        for (int i = 0; i < vector.data.length; i++) {
            sum.data[i] -= vector.data[i];
        }

    }

    public void removeVector(Vector item) {
        vectors.add(item);
    }

    public Vector getmean() {
        return mean;
    }

    public void recomputeClusterMean() {
        for (int i = 0; i < sum.data.length; i++) {
            mean.data[i] = sum.data[i] / vectors.size();
        }
    }

    public boolean contains(Vector vector) {
        return vectors.contains(vector);
    }

    public Set<Vector> getVectors() {
        return vectors;
    }

    public Vector getSum() {
        return sum;
    }
}
